﻿using System;
using System.Collections.Generic;

namespace YJKGridTopologyCal.Planargraph
{
	public class Subgraph
	{
		public Subgraph(PlanarGraph parentGraph)
		{
			this.parentGraph = parentGraph;
		}

		public PlanarGraph GetParent()
		{
			return this.parentGraph;
		}

		public void Add(Edge e)
		{
			if (this.edges.Contains(e))
			{
				return;
			}
			this.edges.Add(e);
			this.dirEdges.Add(e.GetDirEdge(0));
			this.dirEdges.Add(e.GetDirEdge(1));
			this.nodeMap.Add(e.GetDirEdge(0).FromNode);
			this.nodeMap.Add(e.GetDirEdge(1).FromNode);
		}

		public IEnumerator<DirectedEdge> GetDirEdgeEnumerator()
		{
			return this.dirEdges.GetEnumerator();
		}

		public IEnumerator<Edge> GetEdgeEnumerator()
		{
			return this.edges.GetEnumerator();
		}

		public IEnumerator<Node> GetNodeEnumerator()
		{
			return this.nodeMap.GetEnumerator();
		}

		public bool Contains(Edge e)
		{
			return this.edges.Contains(e);
		}

		protected PlanarGraph parentGraph;

		protected HashSet<Edge> edges = new HashSet<Edge>();

		protected IList<DirectedEdge> dirEdges = new List<DirectedEdge>();

		protected NodeMap nodeMap = new NodeMap();
	}
}
